package com.isoft.farm.common.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class SysExceptionAspect {
    private static Logger log= LoggerFactory.getLogger(SysExceptionAspect.class);

    @AfterThrowing(pointcut = "bean(*ServiceImpl)",throwing = "e")
    public void doHandlerException(JoinPoint joinPoint,Throwable e){
        System.out.println("e.class="+e.getClass().getName());
        //获取目标对象类型
        String clsName=joinPoint.getTarget().getClass().getName();
        //获取方法签名
        MethodSignature methodSignature= (MethodSignature) joinPoint.getSignature();
        log.error("{} exception msg is {} ",clsName+"."+methodSignature.getName(),e.getMessage());
    }
}
